package com.smartdio.company.views;

import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.ui.contexts.IContextActivation;
import org.eclipse.ui.contexts.IContextService;
import org.eclipse.ui.part.ViewPart;

public class PersonView extends ViewPart {

	public static final String ID = "com.smartdio.company.views.PersonView"; 
	private Composite top = null;

	private PersonList personList;
	private TableViewer viewer ;

	public PersonView() {
	}

	@Override
	public void createPartControl(Composite parent) {
		top = new Composite(parent, SWT.NONE);
		top.setLayout(new FillLayout());
		personList = new PersonList(top, SWT.NONE);

		IContextService contextService = (IContextService) getSite()
				.getService(IContextService.class);
		IContextActivation contextActivation = contextService
				.activateContext("com.smartdio.company.context");

		viewer = personList.getTableViewer();
		// This is new code
		// First we create a menu Manager
		MenuManager menuManager = new MenuManager();
		Menu menu = menuManager.createContextMenu(viewer.getTable());
		// Set the MenuManager
		viewer.getTable().setMenu(menu);
		getSite().registerContextMenu(menuManager, viewer);
		// Make the selection available
		getSite().setSelectionProvider(viewer);

		personList.getTableViewer().getTable().setMenu(menu);
		viewer.setInput("");
	}

	@Override
	public void setFocus() {
	}

	public PersonList getPersonList() {
		return personList;
	}

	public TableViewer getViewer() {
		return viewer;
	}

}
